package controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.User;
import service.user.UserService;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
    //    controller层调service层
    //自动装配User
    @Autowired
    private UserService userService;
    public void setUserService(UserService userService){
        this.userService=userService;
    }
    @RequestMapping("/personal")
    public String toUserPersonal(Model model,HttpSession session){
        User user = (User) session.getAttribute("id");
        model.addAttribute("user",user);
        return "UserPersonal";//跳转到个人中心
    }
    //更新资料
    @RequestMapping("/personal/update")
    public String updatePersonal(Model model,HttpSession session){
        User user = (User) session.getAttribute("id");
        User userById= userService.queryUserById(user.getCid());
        model.addAttribute("user",userById);
        return "redirect:/user/personal";//重定向到重新加载到个人中心
    }
    //修改密码
    @RequestMapping("/personal/alterpwd")
    public String alterPassword(Model model,HttpSession session){
        User user = (User) session.getAttribute("user");
        User userById= userService.queryUserById(user.getCid());
        model.addAttribute("user",userById);
        return "redirect:/user/personal";//重定向到重新加载到个人中心
    }
}
